package com.quan.WorkTest;

import com.quan.Config.MQConnection;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import org.junit.Test;

public class Publisher {


    @Test
    public void publisher() throws Exception{
        //创建连接
        Connection conn = MQConnection.getRabbitmaConection();

        //创建channel
        Channel channel = conn.createChannel();

        //发布消息到exchange
        for(int i = 0; i < 10; i ++){
            String msg = "Hello-World" + i;
            channel.basicPublish("","Work",null,msg.getBytes());
        }

        System.out.println("生产者发布消息成功");

        //释放资源
        channel.close();
        conn.close();

    }
}
